<template>
  <div class="contract-result-page layout-content">
    <a-result status="success" :title="title">
      <template #extra>
        <p class="btn-list">
          <a-space>
            <a-button @click="toContractDetail">
              查看合同
            </a-button>
            <a-button @click="toDownloadContract">
              下载合同
            </a-button>
          </a-space>
        </p>
        <p class="btn-list" v-if="pages == 'contractPage'">
          <a-space>
            <a-button @click="contractRelocate">
              撤销合同
            </a-button>
            <a-button @click="contractUploadDouble">
              上传双签合同
            </a-button>
          </a-space>
        </p>
      </template>
    </a-result>
  </div>
</template>

<script>
import {
  downloadContractMethod,
  contractDetailMethod,
  contractUploadDoubleMethod,
  contractRelocateMethod
} from "../common/index";
import { getCurIdentity } from "@/util/common";

export default {
  props: {
    title: {
      type: String,
      default: ""
    },
    pages: {
      type: String,
      default: ""
    },
    datas: {
      type: Array,
      default: () => {
        return {};
      }
    }
  },
  data() {
    return {
      contractId: "",
      version: ""
    };
  },
  computed: {
    identity() {
      return getCurIdentity(); //1买家，2卖家
    }
  },
  created() {
    this.contractId = this.datas[0].id;
    if (this.pages == "contractPage") {
      this.version = this.datas[0].version;
    }
    document.body.scrollTop = 0;
    document.documentElement.scrollTop = 0;
  },
  methods: {
    downloadContractMethod,
    contractDetailMethod,
    contractUploadDoubleMethod,
    contractRelocateMethod,
    // 查看合同
    toContractDetail() {
      this.contractDetailMethod(this.identity, this.contractId);
    },
    //合同撤销
    contractRelocate() {
      this.contractRelocateMethod(
        this.contractId,
        this.version,
        this.identity,
        "toContractDetail"
      ).then(res => {
        if (res) {
          // this.$emit("initPage");
        }
      });
    },
    //上传双签合同
    contractUploadDouble() {
      let params = {
        id: this.contractId,
        version: this.version
      };
      this.contractUploadDoubleMethod(params, this.identity);
    },
    //合同下载
    toDownloadContract() {
      this.downloadContractMethod(this.contractId);
    }
  }
};
</script>
<style lang="scss" scoped>
::v-deep .ant-btn {
  width: 116px;
}
::v-deep .ant-result-extra > * {
  margin: 0;
}
.contract-result-page {
  min-height: 800px;
  background: #ffffff;
  .btn-list {
    margin-bottom: 10px;
  }
}
</style>
